<template>
	<view>
		<input type="text" :value="value">
		<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">一键获取手机号</button>
		<button open-type="contact">人工</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value: ''
			}
		},
		onLoad(options) {
			console.log(options,'options')
		},
		methods: {
			async getPhoneNumber(e) {
				console.log(e.detail.code)
				const res = await uni.request({
					url: 'https://api.weixin.qq.com/cgi-bin/token',
					data: {
						grant_type: 'client_credential',
						appid: 'wx2df109819424d2b1',
						secret: '34fc35b13b88e417e470885fe5573f28'
					}
				})
				const {access_token} = res.data;
				console.log(res,'res')
				uni.request({
					url:'https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=' + access_token,
					method:'POST',
					data: {
						code: e.detail.code
					}
				}).then(res => {
					const {phoneNumber} = res.data.phone_info;
					this.value = phoneNumber
				})
			}
		}
	}
</script>

<style>

</style>
